<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>个人印章生成</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            min-height: 100vh;
            margin: 0;
            background-color: white;
            overflow: hidden;
        }
        .input-group {
            display: flex;
            flex-wrap: wrap;
            justify-content: center;
            align-items: center;
            margin-bottom: 20px;
        }
        input {
            padding: 10px;
            margin: 0 5px;
            border: 1px solid #ccc;
            border-radius: 4px;
            width: 200px;
        }
        select {
            padding: 10px;
            margin: 0 5px;
            border: 1px solid #ccc;
            border-radius: 4px;
            width: 200px;
        }
        button {
            padding: 10px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            margin: 0 5px;
        }
        button.generate {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
        }
        button.generate:hover {
            background: linear-gradient(135deg, #566dc7 0%, #683f8d 100%);
        }
        button.cancel {
            background-color: #808080;
            color: white;
        }
        button.cancel:hover {
            background-color: #696969;
        }
        #seal {
            width: 250px;
            height: 250px;
            border: 15px solid transparent;
            border-image: linear-gradient(45deg, #a00, #f00, #a00) 1;
            border-radius: 50%;
            margin-top: 20px;
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 100px;
            color: red;
            font-family: "STXinwei";
            position: relative;
            overflow: hidden;
            writing-mode: vertical-rl;
            text-orientation: upright;
            line-height: 1.2;
            background-color: white;
        }
        #seal::before {
            content: '';
            position: absolute;
            top: 15px;
            left: 15px;
            right: 15px;
            bottom: 15px;
            opacity: 0.5;
        }
        #seal-text {
            text-align: center;
        }
        .modal {
            display: none;
            position: fixed;
            z-index: 1;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            overflow: auto;
            background-color: rgba(0, 0, 0, 0.4);
        }
        .modal-content {
            background-color: #fefefe;
            margin: 15% auto;
            padding: 20px;
            border: 1px solid #888;
            width: 300px;
            border-radius: 8px;
            text-align: center;
            box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
        }
        .close {
            color: #aaa;
            float: right;
            font-size: 28px;
            font-weight: bold;
        }
        .close:hover,
        .close:focus {
            color: black;
            text-decoration: none;
            cursor: pointer;
        }
        @font-face {
            font-family: 'fangyuan14';
            src: url('../font/fangyuan14.ttf');
        }
        @font-face {
            font-family: 'MyFontRegular';
            src: url('../font/MyFont-Regular.ttf');
        }
        @font-face {
            font-family: 'MyCustomFont';
            src: url('../font/MyFont-pen.ttf') format('woff2'),
                 url('../font/MyFont-pen.ttf') format('woff'),
                 url('../font/MyFont-pen.ttf') format('truetype');
            font-weight: normal;
            font-style: normal;
        }
    </style>
</head>
<body>
    <div class="input-group">
        <input type="text" id="name" placeholder="请输入2-3个字的姓名">
        <select id="fontStyle">
            <option value="STXinwei">STXinwei</option>
            <option value="fangyuan14">fangyuan14</option>
            <option value="MyFontRegular">MyFont-Regular</option>
            <option value="MyCustomFont">MyCustomFont</option>
        </select>
        <button class="generate" onclick="generateSeal()">生成</button>
        <button class="cancel" onclick="cancelSeal()">取消</button>
    </div>
    <div id="seal">
        <div id="seal-text"></div>
    </div>
    <div id="myModal" class="modal">
        <div class="modal-content">
            <span class="close">&times;</span>
            <p id="modal-message"></p>
        </div>
    </div>
    <script>
        function generateSeal() {
            const name = document.getElementById('name').value;
            const fontStyle = document.getElementById('fontStyle').value;
            const sealTextElement = document.getElementById('seal-text');
            if (name.length < 2 || name.length > 3) {
                showModal('请输入 2 - 3 个字的姓名');
                return;
            }
            let sealText;
            if (name.length === 2) {
                sealText = `${name}之印`;
            } else {
                sealText = `${name}印`;
            }
            let formattedText = '';
            for (let i = 0; i < sealText.length; i += 2) {
                formattedText = sealText.slice(0, 2) + '<br>' + (i + 2 <= sealText.length ? sealText.slice(i, i + 2) : sealText[i]);
            }
            formattedText = formattedText.trim();
            sealTextElement.innerHTML = formattedText;
            document.getElementById('seal').style.fontFamily = fontStyle;
        }
        function cancelSeal() {
            document.getElementById('name').value = '';
            document.getElementById('seal-text').textContent = '';
            document.getElementById('seal').style.fontFamily = 'STXinwei';
        }
        function showModal(message) {
            const modal = document.getElementById('myModal');
            const modalMessage = document.getElementById('modal-message');
            const closeBtn = document.getElementsByClassName('close')[0];
            modalMessage.textContent = message;
            modal.style.display = 'block';
            closeBtn.onclick = function () {
                modal.style.display = 'none';
            };
            window.onclick = function (event) {
                if (event.target === modal) {
                    modal.style.display = 'none';
                }
            };
        }
    </script>
</body>
</html>
    